package com.atguigu.exer2_2;

public class Triangle {
    private double a;
    private double b;
    private double c;

    public Triangle() {
    }

    public Triangle(double a, double b, double c) {
        //（1）边长不能为负数或0
        //（2）三角形要求任意两边之和大于第三边
        if(a<=0 || b<=0 || c<=0 || a+b<=c || b+c<=a ||a+c<=b){
            System.out.println(a+"," + b +"," + c +"的值无法构成三角形");
        }else {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }

    //get/set
    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }

    //其他方法
    public double area(){
        double p = (a+b+c)/2;
        return Math.sqrt(p * (p-a) * (p-b) * (p-c));
    }

    public double perimeter(){
        return a+b+c;
    }

    public String getInfo(){
        return "三边长：" + a + "," + b +"," + c +
                "，面积：" + area() +
                "，周长：" + perimeter();
    }
}
